﻿layui.use(['comment', 'layer', 'form'], function () {
    var comment = layui.comment
        , form = layui.form
        , layer = layui.layer
        , $ = layui.$;

    comment._ACP(ApiUrl.Config.GetUserConfig, { key: 1 }, function (res) {
        if (res.success) {
            form.val("lanbt-setting-form", JSON.parse(res.result));
        } else {
            comment.Error(res.errorMsg);
        }
    })

    $('#save-setting').click(function () {
        var isValid = form.validate('.password');
        if (!isValid) {
            return;
        }
        var field = form.val('lanbt-setting-form');
        var data = {
            value: JSON.stringify(field),
            userkey: 1
        };

        comment._ACP(ApiUrl.Config.OperationConfig, JSON.stringify(data), function (res) {
            if (res.success) {
                comment.Success(res.result);
            } else {
                comment.Error(res.errorMsg)
            }
        })
    });

    form.verify({
        lanbt_password: function (value, item) {
            if (value.length > 0 && !/^[\S]{6}$/.test(value)) {
                return '密码必须6位，且不能出现空格'
            }
        },
    })
})